package gameservice

import (
	"admin100/app/dao/gamedao"
	"admin100/library/define"
	"admin100/library/define/defErr"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/util/gconv"
)

var PlayerData = playerDataService{}

type playerDataService struct{}

func (s *playerDataService) GetMaxPlayerLevel(node, serverId string, channelList []string) int {
	gameDb := gamedao.NewPlayerDataDao(node)
	playerDb := gamedao.NewPlayerDao(node)

	r, err := gameDb.As("T0").Fields("max(T0."+gameDb.Columns.Level+")").
		InnerJoin(playerDb.Table, "T1",
			"T1."+playerDb.Columns.Id+"="+"T0."+gameDb.Columns.PlayerId).
		Where(g.Map{
			playerDb.Columns.ServerId: serverId,
			playerDb.Columns.Channel:  channelList,
		}).Value()
	defErr.IfPanic(err, define.DataOptFail)
	if r == nil {
		defErr.Panic(define.RecordNodFound)
	}

	return gconv.Int(r.Val())
}
